class Solution(object):
    def isPalindrome(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head or not head.next:
            return True
        # 使用快慢指针找到中心点
        slow = head
        fast = head
        while fast and fast.next:
            fast = fast.next.next
            slow = slow.next
        mid = slow
        # 反转中心点之后的
        pre = None
        while mid:
            nxt = mid.next
            mid.next = pre
            pre = mid
            mid = nxt
        # 因为从中间分开的，所以两边一定一样长
        while pre :
            if pre.val != head.val:
                return False
            pre = pre.next
            head = head.next
        return True